[C++ Error] Unit1.h(12): E2176 Too many types in declaration

来源:百度知道 编辑:UC知道 时间:2024/07/03 04:38:33
总是出现这个错误:
File1.h:
#ifndef H
#define H
#include<iostream>
using namespace std;

class h{

private:
int a;
int b;
public:
h()
{
a=3;
b=5;
}
h(int x,int y)
{
a=x;
b=y;
}
int add();

~h();

}
file1.cpp:
#include"File1.h"

int h::add()
{
return a+b;
}

调用处:
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include"File1.h"
#include <Forms.hpp>
//----------

预处理 的问题

#ifndef ...
#define ...

......

#endif

你没有结束 所以提示错误

---
在#endif截止前,是一直到main
也就是说 ,编译器 一直检测到main函数 如果还没有遇到#endif 说明漏了,则提示错误
但是编译器只检测语法,并不知道你到底在哪儿放的,所以就指向main前

我的看法是这样的
#include <Forms.hpp>中有了 TForm1 声明
你又声明了一次
重复出错

在File1.h末尾加上#endif试试